function ClusterLayer(map, params) {
    this._map = map;
    this._params = Object.assign({
        clusterDistance: 256,
        data: []
    }, params);
    this._data = params.data;
    return this;
}
ClusterLayer.prototype._map2pixel = function (lonlat) {
    return this._map.project(lonlat);
}
ClusterLayer.prototype.init = function () {
    this._showCluster2Map();
}
/**
 * 在地图上聚类
 * @private
 */
ClusterLayer.prototype._showCluster2Map = function () {
    const that = this;
    const features = that._data.features;
    debugger;
    that._clusterData = [];
    for (let i = 0; i < features.length; i++) {
        let clustered = false;
        const feature = features[i];
        for (let j = 0; j < that._clusterData.length; j++) {
            const _cData = that._clusterData[j];
            if (that._clusterTest(feature, _cData.feature)) {
                that._add2ClusterData(j, feature);
                clustered = true;
                break;
            }
        }
        if (!clustered) {
            that._clusterCreate(feature);
        }
    }
    that._showResult2Map();
}
/**
 * 初始化聚类
 * @param feature
 * @private
 */
ClusterLayer.prototype._clusterCreate = function (feature) {
    this._clusterData.push({
        feature: feature,
        cluster: []
    });
}
/**
 * 展示聚类结果
 * @private
 */
ClusterLayer.prototype._showResult2Map = function () {
    const that = this;
    console.log('clusterData', that._clusterData);
}
/**
 * 添加聚类数据
 * @param index
 * @param data
 * @private
 */
ClusterLayer.prototype._add2ClusterData = function (index, data) {
    this._clusterData[index].cluster.push(data);
};
/**
 * 判断是否聚类
 * @param feature
 * @returns {boolean}
 * @private
 */
ClusterLayer.prototype._clusterTest = function (feature, featureCluster) {
    const that = this;
    const coords0Pixel = that._map2pixel(feature.geometry.coordinates);
    const coordsPixel = that._map2pixel(featureCluster.geometry.coordinates);
    const offX = coords0Pixel.x - coordsPixel.x;
    const offY = coords0Pixel.y - coordsPixel.y;
    const dist = Math.sqrt(offX * offX + offY * offY);
    return dist < that._params.clusterDistance;
}
